//
//  MainViewController.m
//  WeiBTest
//
//  Created by Zc_zhou on 15/9/7.
//  Copyright (c) 2015年 Apple. All rights reserved.
//

#import "MainViewController.h"
#import "DiscoverViewController.h"
#import "HomeViewController.h"
#import "MessageViewController.h"
#import "ProfileViewController.h"
#import "WeiNaigationViewController.h"
#import "HWTabBar.h"
@interface MainViewController ()<HWTabBardelegate>

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    HomeViewController *home = [[HomeViewController alloc] init];
    [self addchildWith:home image:@"tabbar_home" selectImage:@"tabbar_home_selected" title:@"首页"];
    MessageViewController *message = [[MessageViewController alloc] init];
    [self addchildWith:message image:@"tabbar_message_center" selectImage:@"tabbar_message_center_selected" title:@"消息"];
    DiscoverViewController *discover = [[DiscoverViewController alloc] init];
    [self addchildWith:discover image:@"tabbar_discover" selectImage:@"tabbar_discover_selected" title:@"发现"];
    ProfileViewController *profile = [[ProfileViewController alloc] init];
    [self addchildWith:profile image:@"tabbar_profile" selectImage:@"tabbar_profile_selected" title:@"我"];
    HWTabBar *tabBar = [[HWTabBar alloc] init];
    tabBar.delegate = self;
    [self setValue:tabBar forKeyPath:@"tabBar"];
    
}

- (void)addchildWith:(UIViewController *)ctrl image:(NSString *)image selectImage:(NSString *)selectImage title:(NSString*)title
{
    ctrl.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    ctrl.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    WeiNaigationViewController *nav = [[WeiNaigationViewController alloc] initWithRootViewController:ctrl];
    ctrl.title = title;
    NSMutableDictionary *normalDictionary = [[NSMutableDictionary alloc] init];
    normalDictionary[NSForegroundColorAttributeName] = HWcolor(123, 123, 123);
    [ctrl.tabBarItem setTitleTextAttributes:normalDictionary forState:UIControlStateNormal];
    NSMutableDictionary *selectDictionary = [[NSMutableDictionary alloc] init];
    selectDictionary[NSForegroundColorAttributeName] = [UIColor orangeColor];
    [ctrl.tabBarItem setTitleTextAttributes:selectDictionary forState:UIControlStateSelected];
    [self addChildViewController:nav];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)tabBarDidClickPlusButton:(HWTabBar *)tabBar
{
    UIViewController *ctrl = [[UIViewController alloc] init];
    ctrl.view.backgroundColor = [UIColor redColor];
    [self presentViewController:ctrl animated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
